<?php

/**
 * Created by PhpStorm.
 * User: zuoa
 * Date: 2016/12/16 0016
 * Time: 14:08
 */
class Employee_model extends Y_Model
{
    public function add_record($r)
    {
        return $this->db->insert("tbl_employee", $r);
    }

    public function get_employee($id)
    {
        $query = $this->db->where("openid", $id)->get("tbl_employee");
        return $query->first_row();
    }

    public function upsert($e)
    {
        $this->db->trans_start();
        $user = $this->get_employee($e["openid"]);
        if (is_null($user)) {
            $this->db->insert("tbl_employee", $e);
        } else {
            $this->db->where('openid', $e["openid"])->update("tbl_employee", $e);
        }
        $this->db->trans_complete();
    }
}